/**
 * This Class will implement the rates class for each lot.
 * 
 * @author Gil Levinson
 * @author Boris Fradlis
 * @author Yogev Levi
 * @author Hila Porat
 * 
 */

package vcpClasses;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import system.VCP;

// Start of Rates ********************************************************************

public class Rates implements Serializable{
	
	//Class variables ****************************************************************
	
	private float occasional;
	private float advance;
	private float normalSubHours;
	private float fullSubHours;
	
	// Constructors ******************************************************************
	
	/**
	 * Constructor using the following fields:
	 * @param occ the occasional rate
	 * @param adv the In advance order rate
	 */
	
	public Rates(float occ, float adv, float normHours, float fullHours){
		this.setOccasional(occ);
		this.setAdvance(adv);
		this.normalSubHours = normHours;
		this.fullSubHours = fullHours;
	}
	
	/**
	 * No implementation constructor
	 */
	
	public Rates(){
		occasional=this.getOccasional();
		advance=this.getAdvance();
		normalSubHours=this.getNormalSubHours();
		fullSubHours = this.getFullSubHours();
	}

	// instance method ***************************************************************************************	
		
	
	/**
	 * this method calculate the difference between the two giving time as String
	 * @param timeStart 
	 * @param timeStop
	 * @return time[0]=hh, time[1]=mm,
	 */
	public int[] timeDiff(String timeStart,String timeStop )
	{
		java.util.Date d1 = null;
		java.util.Date d2 = null;
		int time[]=new int[2];
		SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss"); 
		try {
		    d1 = format.parse(timeStart);
		    d2 = format.parse(timeStop);
		} catch (ParseException e) {
		    e.printStackTrace();
		}    
		// Get msec from each, and subtract.
		long diff = d2.getTime() - d1.getTime();       
		long diffMinutes = diff / (60 * 1000);         
		long diffHours = diff / (60 * 60 * 1000); 
		time[0]=(int) diffHours;
		time[1]=(int) diffMinutes/60;
		return time;

	}

	/**
	 * This method will initiate new string which will represent the content request for rates change for the current lot  
	 * @return the content string
	 */
	public String toSettingRequest(){
		return new String("Request sent from "+VCP.currentUser.getUserFirstName()+" "+VCP.currentUser.getUserLastName()+"\nLot No."+VCP.currentLot.getParkingLotNumber()+
				"\n\nOccasional Order : " +occasional+ "\nIn-Advance Order : " +advance + "\nNormal Hours : "+normalSubHours + "\nFull Hours : "+ fullSubHours);
	}
	
	// Getters and Setters *****************************************************************************************************************

	/**
	 * @return the occasional
	 */
	public float getOccasional() {
		return occasional;
	}

	/**
	 * @param occasional the occasional to set
	 */
	public void setOccasional(float occasional) {
		this.occasional = occasional;
	}

	/**
	 * @return the advance
	 */
	public float getAdvance() {
		return advance;
	}

	/**
	 * @param advance the advance to set
	 */
	public void setAdvance(float advance) {
		this.advance = advance;
	}

	/**
	 * @return the normalSubSingle
	 */
	public float getNormalSubHours() {
		return normalSubHours;
	}

	/**
	 * @param normalSubSingle the normalSubSingle to set
	 */
	public void setNormalSubHours(float normalSubSingle) {
		this.normalSubHours = normalSubSingle;
	}

	/**
	 * @return the fullSubSingle
	 */
	public float getFullSubHours() {
		return fullSubHours;
	}

	/**
	 * @param fullSubSingle the fullSubSingle to set
	 */
	public void setFullSubHours(float fullSubSingle) {
		this.fullSubHours = fullSubSingle;
	}
	

	
}
